

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class DurationList implements List<Duration>{
	
	
	List<Duration> list;
	private final int maxSize;

	public DurationList(int maxSize) {
		this.maxSize = maxSize;
		
		list = new ArrayList<Duration>(maxSize);
		
	}
	
	
	public int size() {
		return list.size();
	}

	
	public boolean isEmpty() {
		return list.isEmpty();
	}

	
	public boolean contains(Object o) {
		return list.contains(o);
	}

	
	public Iterator<Duration> iterator() {
		return list.iterator();
	}

	
	public Object[] toArray() {
		return list.toArray();
	}

	
	public <T> T[] toArray(T[] a) {
		return list.toArray(a);
	}

	
	public boolean add(Duration e) {
		list.add(e);
		int firstIndex = 0;
		if(list.size() > maxSize) {
			firstIndex = list.size() - maxSize;
		}
		list = list.subList(firstIndex, list.size());
		return true;
	}

	
	public boolean remove(Object o) {
		return list.remove(o);
	}

	
	public boolean containsAll(Collection<?> c) {
		return list.containsAll(c);
	}

	
	public boolean addAll(Collection<? extends Duration> c) {
		return list.addAll(c);
	}

	
	public boolean addAll(int index, Collection<? extends Duration> c) {
		return list.addAll(index, c);
	}

	
	public boolean removeAll(Collection<?> c) {
		return list.removeAll(c);
	}

	
	public boolean retainAll(Collection<?> c) {
		return list.retainAll(c);
	}

	
	public void clear() {
		list.clear();
	}

	
	public Duration get(int index) {
		return list.get(index);
	}

	
	public Duration set(int index, Duration element) {
		return list.set(index, element);
	}

	
	public void add(int index, Duration element) {
		if(index > maxSize-1 || index < 0) {
			throw new IndexOutOfBoundsException("Index " + index + " is not between 0 and " + (maxSize-1) );
		} else {
			list.add(index, element);
		}
		
	}

	
	public Duration remove(int index) {
		return list.remove(index);
	}

	
	public int indexOf(Object o) {
		return list.indexOf(o);
	}

	
	public int lastIndexOf(Object o) {
		return list.lastIndexOf(o);
	}

	
	public ListIterator<Duration> listIterator() {
		return list.listIterator();
	}

	
	public ListIterator<Duration> listIterator(int index) {
		return list.listIterator(index);
	}

	
	public List<Duration> subList(int fromIndex, int toIndex) {
		return list.subList(fromIndex, toIndex);
	}

}
